<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        a {
            text-decoration: none;
            color: #333;
            /* font-size: 24px; */
        }
        
        .login-header {
            text-align: center;
            font-size: 24px;
        }
        
        .login {
            position: fixed;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            display: none;
            border: #ebebeb solid 1px;
            box-shadow: 0px 0px 20px #ddd;
            background-color: #fff;
            width: 512px;
            height: 280px;
        }
        
        .login-title {
            position: relative;
            width: 100%;
            margin: 10px 0 0 0;
            text-align: center;
            height: 40px;
            line-height: 40px;
            font-size: 18px;
            cursor: move;
        }
        
        .login-input-content {
            margin-top: 20px;
        }
        
        .login-title span {
            position: absolute;
            right: -20px;
            top: -30px;
            font-size: 12px;
            background-color: #fff;
            border: #ebebeb 1px solid;
            width: 40px;
            height: 40px;
            border-radius: 20px;
        }
        
        .login-title span a {
            display: block;
        }
        
        .login-input {
            overflow: hidden;
            margin: 0px 0px 20px 0px;
        }
        
        .login-input label {
            float: left;
            width: 90px;
            padding-left: 10px;
            text-align: right;
            height: 35px;
            line-height: 35px;
            font-size: 14px;
        }
        
        .login-input input.list-input {
            float: left;
            border: #ebebeb 1px solid;
            width: 350px;
            line-height: 35px;
            height: 35px;
            text-indent: 5px;
        }
        
        .login-button {
            width: 50%;
            margin: 30px auto 0px auto;
            line-height: 40px;
            font-size: 14px;
            border: #ebebeb 1px solid;
            text-align: center;
        }
        
        .login-bg {
            position: fixed;
            top: 0px;
            left: 0px;
            width: 100%;
            height: 100%;
            display: none;
            background: rgba(0, 0, 0, .3);
        }
    </style>
</head>

<body>
    <div class="login-header"><a id="link" href="javascript:;">点击弹出登录框</a></div>
    <div class="login-bg">
    </div>
    <div class="login">
        <div class="login-title" id="title">登录会员
            <span><a href="javascript:;" id="closeBtn" class="close-login">关闭</a></span>
            <div class="login-input-content">
                <div class="login-input">
                    <label for="">用户名：</label>
                    <input type="text" placeholder="请输入用户名" name="info[username]" id="username" class="list-input">
                </div>
                <div class="login-input">
                    <label for="">密码：</label>
                    <input type="password" placeholder="请输入密码" name="info[password]" id="password" class="list-input">
                </div>
            </div>
            <div id="loginBtn" class="login-button"><a href="javascript:void(0);" id="login-button-submit">登录会员</a></div>
        </div>
    </div>
    <script>
        var loginView = document.querySelector('.login');
        var loginBG = document.querySelector('.login-bg');
        var loginBtn = document.querySelector('#link');
        var closeBtn = document.querySelector('#closeBtn');

        var title = document.querySelector('#title');

        loginBtn.addEventListener('click', function() {
            // 显示登录框
            loginView.style.display = 'block';
            loginBG.style.display = 'block';
        });

        closeBtn.addEventListener('click', function() {
            // 隐藏登录框
            loginView.style.display = 'none';
            loginBG.style.display = 'none'
        });

        // 开始拖拽
        // 1. 鼠标按下获取鼠标在盒子内的坐标
        title.addEventListener('mousedown', function(e) {
            var x = e.pageX - loginView.offsetLeft;
            var y = e.pageY - loginView.offsetTop;
            // 鼠标移动 让登录框跟随鼠标
            document.addEventListener('mousemove', move);

            function move(e) {
                loginView.style.left = e.pageX - x + 'px';
                loginView.style.top = e.pageY - y + 'px';
            }

            // 鼠标弹起事件 让鼠标移动事件移除
            document.addEventListener('mouseup', function(e) {
                document.removeEventListener('mousemove', move);
            });
        });
    </script>
</body>

</html>